;
$(function () {
  $.validator.addMethod("checkName", function (val) {
    return /^[a-z]\w+/i.test(val);
  })
  $("form").validate({
    errorPlacement: function (error, element) {
      // element.parents().find(".eron").html("")

      $(element).parents().find(".eron").children().text("")
      $(element).parents().find(".eron").append(error);
    },
    success: function (lable) {
    },
    errorElement: "span",
    rules: {
      user: {
        digits: true,
        rangelength: [11, 11]
      },
      upwd: {
        required: true,
        rangelength: [6, 18]
      },
      upwd2: {
        equalTo: "#pass"
      },
      uname: {
        required: true,
        remote:"./account/checkname"
      }

    },
    messages: {
      user: {
        digits: "手机号码只能数字",
        rangelength: "手机号必须11位"
      },
      upwd: {
        required: "密码必填",
        rangelength: "密码长度必须{0}-{1}"
      },
      upwd2: {
        equalTo: "2次密码不一致"
      },
      uname: {
        required: "用户名必填",
        remote: "该用户已经被注册"
      }
    },
    submitHandler() {
      $.ajax({
        url: "./account/reg",
        type: 'post',
        data: $("form").serialize()
      }).then(function (response) {
        layer.msg("注册成功");
        if (response.status == 200) {
          layer.msg("注册成功")
        } else {
          layer.msg("注册失败")
        }
      })

      return false
    }
  })
    $(".yz").on("click",function () {
        location="login.html"
    })
})